<template>
    <div class="m-user">
      <template v-if="user">
        欢迎您，<span class="username">{{user}}</span>
        <nuxt-link to="/exit">退出</nuxt-link>
      </template>
      <template v-else>
        <nuxt-link to="/login" class="login">立即登录</nuxt-link>
        <nuxt-link to="/rejister" class="register">注册</nuxt-link>
      </template>
    </div>
</template>

<script type="text/ecmascript-6">
export default {
  data () {
    return {
      user: ''
    }
  },
  async mounted() {
    const {status,data} = await this.$axios.get('http://localhost:3200/users/getUser')
    if (status === 200) {
      if (data && data.code ===0) {
        this.user = data.user
      }
    }
  }
}
</script>

<style lang="scss">

</style>
